#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@File   : StorageView.py
@Time : 2024/12/9 14:04
@Author: Wangwc
@Describe:  存储管理总览相关接口
"""
from utils.requests_tools import HttpRequest,check_response,retry_func
from utils.login import Login
from commons.logger import log
from utils.ssh_tools import create_ssh_client_as_root, create_raid_with_shell

assert_message = {'code': 200, 'msg': 'success'}


class StorageView:

    def __init__(self, u_token):
        self.http = HttpRequest(u_token)

    @check_response(check = {"msg": "success"})
    def get_tasks(self):
        """
        获取定时任务列表
        :return:
        """
        path = '/ugreen/v1/storage/overview/cron/tasks'
        response = self.http.get(path)
        return response

    def get_iops(self,type = 1):
        """
        获取性能相关数据
        :param type: 1:获取存储空间性能，2：获取硬盘实时性能
        :return:
        """
        path = "/ugreen/v1/storage/volume/iops"
        parms = {"type":type,'interval':5}
        response = self.http.get(path,params=parms)
        return response

    def get_pool_list(self):
        """
        获取存储空间状态信息
        :return:
        """
        path = "/ugreen/v1/storage/pool/list"
        response = self.http.get(path)
        return response

    def get_disk_list(self):
        """
        获取硬盘状态信息（基本信息）
        :return:
        """
        path = "/ugreen/v2/storage/disk/list"
        response = self.http.get(path)
        return response

    def get_disk_vars(self):
        """
        获取硬盘温度信息
        :return:
        """
        path = "/ugreen/v1/storage/disk/vars"
        response = self.http.get(path)
        return response


    def get_disk_runningState(self,disk):
        """
        获取硬盘的详细信息-运行状况
        :param disk: 硬盘名称 /dev/sda
        :return:
        """
        path = "/ugreen/v1/storage/disk/runningState"
        params = {"disk": f"{disk}"}
        response = self.http.get(path,params=params)
        return response

    def get_disk_attribute(self,disk):
        """
        获取硬盘的详细信息-基本属性
        :param disk: 硬盘名称 /dev/sda
        :return:
        """
        path = "/ugreen/v1/storage/disk/attribute"
        params = {"disk": f"{disk}"}
        response = self.http.get(path,params=params)
        return response


    def get_disk_smartinfo(self,disk):
        """
        获取硬盘的详细信息-S.M.A.R.T.信息
        :param disk: 硬盘名称 /dev/sda
        :return:
        """
        path = "/ugreen/v1/storage/disk/benchmark/info"
        params = {"disk": f"{disk}"}
        response = self.http.get(path,params=params)
        return response


    def start_FIO_check(self,disk):
        """
        启动FIO读写性能检测
        :param disk: 硬盘名称 /dev/sda
        :return:
        """
        path = "/ugreen/v1/storage/disk/benchmark/start"
        data = {"disk": f"{disk}"}
        response = self.http.post(path,json=data)
        return response

    def get_FIO_result(self,disk):
        """
        获取FIO检测进展，确认检测已完成
        :param disk: 硬盘名称 /dev/sda
        :return:
        """
        path = "/ugreen/v1/storage/disk/benchmark/running"
        params = {"disk": f"{disk}"}
        headers = '[object Object]'
        response = self.http.get(path,params=params,headers=headers)
        return response




if __name__ == "__main__":
    pass
